IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'WebsiteCreate')
	BEGIN
		DROP  Procedure  WebsiteCreate
	END

GO

CREATE Procedure WebsiteCreate
(
	@guid nvarchar(50),
	@clientGuid nvarchar(50),
	@title nvarchar(200),
	@typeFlags int,
	@websiteId int output
)
AS

DECLARE @clientId int
SELECT @clientId = ClientId FROM Clients WHERE Guid = @clientGuid

IF @clientId IS NULL
	RAISERROR ('Client with specified GUID does not exist.', 11, 1)

INSERT INTO Websites
	(ClientId, Guid, TypeFlags, Title, CreateDate, UpdateDate)
VALUES
	(@clientId, @guid, @typeFlags, @title, GETDATE(), GETDATE())
	
SET @websiteId = SCOPE_IDENTITY()

GO